<!--考核记录-->
<template>
  <div class="checkListContainer">
    <!--头部bar开始-->
    <CommonBar :options="options"></CommonBar>
    <!--头部bar结束-->
    <div class="ListContent" v-for="(item, index) in List" :key="index">
      <div class="content" @click="toDetail(item.id,item.statu)">
        <p class="contentleft">{{item.district_name}}/{{item.cleaner_name}}</p>
        <p class="contentright">{{item.update_date}}</p>
      </div>
    </div>
    <div class="noData" v-show="List.length==0">
      <van-image width="163px" height="120px" fit="contain" :src="nochekData" />
      <p>暂无数据 ！</p>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
import CommonBar from "../../common/commonBar";
export default {
  components: {
    CommonBar
  },

  data() {
    return {
      options: {
        type: "icon",
        centerText: "历史考核明细",
        iconNname: "wap-home",
        lefttype: "left"
      },
      nochekData: require("../../../../static/image/nochekData.png"),
      List: [],
      duty_id: "",
      signdate: ""
    };
  },
  created() {
    this.signdate = this.$route.query.signdate;
    console.log(this.signdate.split("-")[0], this.signdate.split("-")[1]);
    this.duty_id = this.$route.query.id;
    this.showdate();
  },
  mounted() {
    this.getLoadData();
  },
  computed: {
    ...mapState({
      token: state => state.Authorization,
      user_department_type: state => state.userData.department_type, //人员类型
      user_department_id: state => state.userData.department_id // 人员id
    })
  },
  methods: {
    //记录
    getLoadData() {
      this.$toast.loading({
        mask: true,
        message: "加载中...",
        duration: 5000
      });
      var params = {
        token: this.token,
        duty_id: this.duty_id,
        district_id: this.user_department_id,
        start_date: this.start_date,
        end_date: this.end_date
      };
      this.$http
        .get(`${this.$basePath}?service=App.Cleaner.GetCheckList&api=86`, {
          params: params
        })
        .then(res => {
          if (res.ret == 200) {
            this.$toast.clear();
            this.List = res.data.list;
            console.log("个人历史记录", this.List);
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    //当月最后一天
    showdate() {
      var fullYear = this.signdate.split("-")[0];
      var month = this.signdate.split("-")[1];
      function getLastDay(year, month) {
        var new_year = year; //取当前的年份
        var new_month = month++; //取下一个月的第一天，方便计算（最后一天不固定）
        var new_date = new Date(new_year, new_month, 1); //取当年当月中的第一天
        return new Date(new_date.getTime() - 1000 * 60 * 60 * 24).getDate(); //获取当月最后一天日期
      }
      var lastday = getLastDay(fullYear, month);
      this.start_date = this.signdate + "-01";
      this.end_date = this.signdate + "-" + lastday;
    },
    //保洁员考核详情
    toDetail(id, statu) {
      this.$router.push({
        //核心语句
        path: "/cleanerCheckUpdate", //跳转的路径
        query: {
          //路由传参时push和query搭配使用 ，作用时传递参数
          id,
          statu
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
@import "../../../assets/css/check";
</style>